package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    //分页
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) " +
            "values" + "(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addDish(Dish dish);

    @Select("select id from dish where dish.name=#{name}")
    Long getDishIdByName(String name);

    @Select("select * from dish d where d.id=#{id}")
    Dish getDishById(Long id);

    @Update("update dish set name=#{name},category_id=#{categoryId},price=#{price},image=#{image},description=#{description},status=#{status},create_time=#{createTime},update_time=#{updateTime},create_user=#{createUser},update_user=#{updateUser} where id=#{id}")
    void updateDish(Dish dish);

    @Update("update dish set status=#{status} where id=#{id}")
    void stopAndStart(Integer status, Integer id);

    @Delete("delete from dish where id=#{id} ")
    void deleteDish(Integer id);

    void deleteByIds(List<Long> ids);

    //客户端菜品浏览
    @Select("select * from dish where category_id=#{id} and status=1")
    List<Dish> getDishList(Long id);


    @Select("select count(*) from dish where status=1")
    Integer getDishOverSold();
    @Select("select count(*) from dish where status=0")
    Integer getDishOverdisContinued();
}
